//
//  YYJLCenteController.m
//  YuanyangJinlou
//
//  Created by mac004 on 2016/12/26.
//  Copyright © 2016年 suli19910309@qq.com. All rights reserved.
//

#import "YYJLCenteController.h"
#import "YYJLExchangeController.h"
#import "YYJLIntegralController.h"
@interface YYJLCenteController ()
{
    UIView  * blureyView;//覆盖层
    UIImageView  * tipView;//提示框
    UIView * headerView;
}
@end

@implementation YYJLCenteController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self setTitleView:@"我的"];
    [self setRightBarItems:[self SignBtn]];
    
    [self creatUI];
    blureyView=[[UIView alloc]initWithFrame:self.view.bounds];
    blureyView.backgroundColor=[UIColorFromHex(0x000000) colorWithAlphaComponent:.4];
    [self.view addSubview:blureyView];
    blureyView.hidden=YES;
    [self.view sendSubviewToBack:blureyView];
    
    [self addTipView];

}
-(UIButton*)SignBtn{
    UIImage* img=[UIImage imageNamed:@"ico_qiandao"];//16*16
    UILabel * lab=[MyControl createLabelWithFrame:CGRectMake(21*PER_WIDTH, 2*PER_HEIGHT, 24*PER_WIDTH, 12*PER_HEIGHT) Font:12 Text:@"签到" Color:FEELT_COLOR];
    lab.tag=99;
    UIImageView * im =[[UIImageView alloc]initWithFrame:CGRectMake(0, 0, img.size.width, img.size.height)];
    im.tag=98;
    im.image=img;
    
    UIButton * btn=[MyControl createButtonWithFrame:CGRectMake(0, 0, 35*PER_WIDTH, 16*PER_HEIGHT) ImageName:@"" Target:self Action:@selector(sign) Title:@""];
    btn.backgroundColor=[UIColor clearColor];
    [btn addSubview:im];
    [btn addSubview:lab];
    return btn;
}
-(void)sign{
    
    NSLog(@"正在签到");
    [self addTipView];
}

#pragma mark--签到成功
-(void)signSuccess{
    
}
-(void)creatUI{
    [self addHeaderView];
    [self addMiddleView];
}
#pragma mark--头部view
-(void)addHeaderView{
    headerView =[[UIView alloc]initWithFrame:CGRectMake(0, 64, SCREEN_WIDTH, 150*PER_HEIGHT)];
    headerView.backgroundColor=WHITE_COLOR;
    [self.view addSubview:headerView];
    
    //头像
    UIImageView * headerImg=[[UIImageView alloc]initWithFrame:CGRectMake(25*PER_WIDTH, 22*PER_HEIGHT, 60*PER_WIDTH, 60*PER_WIDTH)];
    headerImg.image=[UIImage imageNamed:@"touxiang1_100x100"];
    headerImg.layer.cornerRadius=headerImg.height/2;
    headerImg.layer.masksToBounds=YES;
    [headerView addSubview:headerImg];
    
    //姓名
    UILabel * name =[MyControl createLabelWithFrame:CGRectMake(headerImg.right+15*PER_WIDTH, 34*PER_HEIGHT, 58, 18*PER_HEIGHT) Font:18 Text:@"邹奥,背锅侠" Color:BLACK_COLOR];
    CGFloat width = [name.text boundingRectWithSize:CGSizeMake(1000, 18*PER_HEIGHT) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:name.font} context:nil].size.width;
    name.width=width;
    [headerView addSubview:name];

    //等级
    UIImage* levelImg=[UIImage imageNamed:@"1"];
    UIImageView * level =[[UIImageView alloc]initWithFrame:CGRectMake(name.right+10*PER_WIDTH, name.bottom-levelImg.size.height*PER_HEIGHT, levelImg.size.width*PER_WIDTH, levelImg.size.height*PER_WIDTH)];
    level.image=levelImg;
    [headerView addSubview:level];
    
    //职位
    UILabel * postion =[MyControl createLabelWithFrame:CGRectMake(name.left, name.bottom+10*PER_HEIGHT, 16, 13*PER_HEIGHT) Font:13 Text:@"店长" Color:FEELT_COLOR];
    CGFloat width1 = [postion.text boundingRectWithSize:CGSizeMake(1000, 13*PER_HEIGHT) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:postion.font} context:nil].size.width;
    postion.width=width1;
    [headerView addSubview:postion];
    
    //分割线
    UIView * line1 =[[UIView alloc]initWithFrame:CGRectMake(postion.right+20*PER_WIDTH, postion.top, 1, postion.height)];
    line1.backgroundColor=FEELT_COLOR;
    [headerView addSubview:line1];
    
    //账号
    UILabel * accout =[MyControl createLabelWithFrame:CGRectMake(line1.right+20*PER_WIDTH, postion.top, 120, postion.height) Font:13 Text:@"zouaobeiguoxia" Color:FEELT_COLOR];
    [headerView addSubview:accout];
    //积分按钮
    UIButton*integralBtn =[MyControl createButtonWithFrame:CGRectMake(0, headerView.height-16*PER_HEIGHT-13*PER_HEIGHT, (headerView.width-1)/2, 13*PER_HEIGHT) ImageName:@"" Target:self Action:@selector(integralBtn) Title:@""];
    [headerView addSubview:integralBtn];
    
    UILabel *integral=[MyControl createLabelWithFrame:CGRectMake(70*PER_WIDTH, 0, 26*PER_WIDTH, 13*PER_HEIGHT) Font:13 Text:@"积分" Color:BLACK_COLOR];
    [integralBtn addSubview:integral];
    
    UILabel * numI=[MyControl createLabelWithFrame:CGRectMake(integral.right+8*PER_WIDTH, 0, 100, 13*PER_HEIGHT) Font:13 Text:@"132" Color:TINK_COLOR];
    numI.font=[UIFont fontWithName:HLT size:13*PER_WIDTH];
    [integralBtn addSubview:numI];
    //分割线
    UIView * line2=[[UIView alloc]initWithFrame:CGRectMake(headerView.width/2, integralBtn.top-3*PER_HEIGHT, 0.5, 20*PER_HEIGHT)];
    line2.backgroundColor=UIColorFromHex(0xcccccc);
    [headerView addSubview:line2];
    //发帖数按钮
    //积分按钮
    UIButton*postBtn =[MyControl createButtonWithFrame:CGRectMake(line2.right, headerView.height-16*PER_HEIGHT-13*PER_HEIGHT, (headerView.width-1)/2, 13*PER_HEIGHT) ImageName:@"" Target:self Action:@selector(postBtn) Title:@""];
    
    [headerView addSubview:postBtn];
    
    
    NSString* test=@"1234";
    CGFloat widthP=[test boundingRectWithSize:CGSizeMake(1000, 13*PER_HEIGHT) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:13*PER_WIDTH]} context:nil].size.width;
    
    UILabel * numP=[MyControl createLabelWithFrame:CGRectMake(postBtn.width-70*PER_WIDTH-widthP, 0, widthP, 13*PER_HEIGHT) Font:13 Text:test Color:TINK_COLOR];
    numI.font=[UIFont fontWithName:HLT size:13*PER_WIDTH];
    [postBtn addSubview:numP];
    
    UILabel *integralP=[MyControl createLabelWithFrame:CGRectMake(numP.left-8*PER_WIDTH-26*PER_WIDTH, 0, 26*PER_WIDTH, 13*PER_HEIGHT) Font:13 Text:@"帖子" Color:BLACK_COLOR];
    [postBtn addSubview:integralP];
    

}
//帖子按钮
-(void)postBtn{
    
}
//积分按钮
-(void)integralBtn{
    YYJLIntegralController * integral =[[YYJLIntegralController alloc]init];
    [self.navigationController pushViewController:integral animated:YES];
}
#pragma mark--中间区域
-(void)addMiddleView{
    NSArray* picArr=@[@"ico_xuexijilu",@"ico_kaoshijilu",@"ico_duihuan"];
    NSArray* titleArr=@[@"学习记录",@"考试记录",@"我的兑换"];
    for (int i =0; i<3; i++) {
        UIView * view =[[UIView alloc]initWithFrame:CGRectMake(0,headerView.bottom+20*PER_HEIGHT+i*55*PER_HEIGHT , SCREEN_WIDTH, 45*PER_HEIGHT)];
        view.backgroundColor=WHITE_COLOR;
        view.tag=1000+i;
        [self.view addSubview:view];
        UITapGestureRecognizer *tap=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tap:)];
        view.userInteractionEnabled=YES;
        [view addGestureRecognizer:tap];
        
        UIImageView * img=[[UIImageView alloc]initWithFrame:CGRectMake(23*PER_WIDTH, 13*PER_HEIGHT, 20*PER_WIDTH, 17*PER_HEIGHT)];
        img.image=[UIImage imageNamed:picArr[i]];
        [view addSubview:img];
        
        UILabel * lab =[MyControl createLabelWithFrame:CGRectMake(img.right+18*PER_WIDTH, 15*PER_HEIGHT, 90, 15*PER_HEIGHT) Font:15 Text:titleArr[i] Color:BLACK_COLOR];
        [view addSubview:lab];
        
        UIImageView * arrow =[[UIImageView alloc]initWithFrame:CGRectMake(view.width-20*PER_WIDTH-8*PER_WIDTH, 16*PER_HEIGHT, 8*PER_WIDTH, 14*PER_HEIGHT)];
        arrow.image=[UIImage imageNamed:@"ico_more"];
        [view addSubview:arrow];
        
        
    }
    //设置
    
    UIView * shezhi =[[UIView alloc]initWithFrame:CGRectMake(0, headerView.bottom+195*PER_HEIGHT, SCREEN_WIDTH, 45*PER_HEIGHT)];
    shezhi.backgroundColor=WHITE_COLOR;
    shezhi.tag=1003;
    [self.view addSubview:shezhi];
    UITapGestureRecognizer *tap=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tap:)];
    shezhi.userInteractionEnabled=YES;
    [shezhi addGestureRecognizer:tap];
    
    UIImageView * img=[[UIImageView alloc]initWithFrame:CGRectMake(23*PER_WIDTH, 13*PER_HEIGHT, 20*PER_WIDTH, 17*PER_HEIGHT)];
    img.image=[UIImage imageNamed:@"ico_shezhi"];
    [shezhi addSubview:img];
    
    UILabel * lab =[MyControl createLabelWithFrame:CGRectMake(img.right+18*PER_WIDTH, 15*PER_HEIGHT, 90, 15*PER_HEIGHT) Font:15 Text:@"设置" Color:BLACK_COLOR];
    [shezhi addSubview:lab];
    
    UIImageView * arrow =[[UIImageView alloc]initWithFrame:CGRectMake(shezhi.width-20*PER_WIDTH-8*PER_WIDTH, 16*PER_HEIGHT, 8*PER_WIDTH, 14*PER_HEIGHT)];
    arrow.image=[UIImage imageNamed:@"ico_more"];
    [shezhi addSubview:arrow];

    
}
-(void)tap:(UITapGestureRecognizer*)sender{
    YYJLExchangeController * exchange=[[YYJLExchangeController alloc]init];
    
    
    switch (sender.view.tag) {
        case 1000:
            
            break;
        case 1001:
            break;
        case 1002:
            [self.navigationController pushViewController:exchange animated:YES];
            break;
        case 1003:
            break;
        default:
            break;
    }
}
#pragma mark --提示框
-(void)addTipView{
    
    blureyView.hidden=NO;
    [self.view bringSubviewToFront:blureyView];
    tipView =[[UIImageView alloc]initWithFrame:CGRectMake(37*PER_WIDTH, 140*PER_HEIGHT, SCREEN_WIDTH-74*PER_WIDTH, 410*PER_HEIGHT)];
    tipView.image=[UIImage imageNamed:@"pop_qiandao"];
    tipView.userInteractionEnabled=YES;
    [blureyView addSubview:tipView];
    

    //删除按钮
    UIButton *guanbiBtn=[MyControl createButtonWithFrame:CGRectMake(tipView.width-33*PER_WIDTH, 10*PER_HEIGHT, 23*PER_WIDTH, 23*PER_WIDTH) ImageName:@"ico_guanbi" Target:self Action:@selector(guanbi) Title:@""];
    [tipView addSubview:guanbiBtn];
    
    
    UILabel * tipLb=[MyControl createLabelWithFrame:CGRectMake(0, 65*PER_HEIGHT, tipView.width, 18*PER_HEIGHT) Font:18 Text:@"已连续签到" Color:WHITE_COLOR];
    tipLb.textAlignment=NSTextAlignmentCenter;
       [tipView addSubview:tipLb];
    
    UILabel * sureLb=[MyControl createLabelWithFrame:CGRectMake(0, tipLb.bottom+20*PER_HEIGHT, tipView.width, 18*PER_HEIGHT) Font:18 Text:@"2天" Color:UIColorFromHex(0xdea556)];
    sureLb.textAlignment=NSTextAlignmentCenter;
    
    [tipView addSubview:sureLb];
    //连续签到提示
    UILabel * lab =[MyControl createLabelWithFrame:CGRectMake(0, 195*PER_HEIGHT, tipView.width, 15*PER_HEIGHT) Font:15 Text:@"连续签到7天可获得最大积分哦" Color:BLACK_COLOR];
    lab.textAlignment=NSTextAlignmentCenter;
    [tipView addSubview:lab];
    //签到区
    UIImage * img =[UIImage imageNamed:@"ico-watch"];//37*51
    for (int i =0; i<7; i++) {
        int j=i/4;
        int x=i;
        if (i>3) {
            x=i-4;
        }
        UIImageView * watch =[[UIImageView alloc]initWithFrame:CGRectMake(51*PER_WIDTH+x*51*PER_WIDTH, lab.bottom+20*PER_HEIGHT+j*61*PER_HEIGHT, 37*PER_WIDTH, 51*PER_HEIGHT)];
        watch.image=img;
        watch.tag=100+i;
        
      //  UILabel * la=[MyControl createLabelWithFrame:CGRectMake(<#CGFloat x#>, <#CGFloat y#>, <#CGFloat width#>, <#CGFloat height#>) Font:<#(int)#> Text:<#(NSString *)#> Color:<#(UIColor *)#>]
        [tipView addSubview:watch];
    }
    
    //签到按钮
    UIButton * cancelBtn=[UIButton buttonWithType:UIButtonTypeCustom];
    cancelBtn.frame=CGRectMake(55.5*PER_WIDTH, tipView.height-54*PER_HEIGHT, 190*PER_WIDTH, 39*PER_WIDTH);
    cancelBtn.layer.cornerRadius=cancelBtn.height/2;
    cancelBtn.backgroundColor=TINK_COLOR;
    cancelBtn.titleLabel.font=[UIFont fontWithName:HSGBW3 size:16];
    cancelBtn.titleLabel.font=[UIFont systemFontOfSize:16*PER_HEIGHT];
    [cancelBtn setTitle:@"签到" forState:0];
    [cancelBtn setTitleColor:WHITE_COLOR forState:0];
    [cancelBtn addTarget:self action:@selector(cancelBtn) forControlEvents:UIControlEventTouchUpInside];
    [tipView addSubview:cancelBtn];
    
    
    
    
}
#pragma mark--签到
-(void)cancelBtn{
    for (id view in tipView.subviews) {
        [view removeFromSuperview];
    }
    tipView.image=[UIImage imageNamed:@"img_qiandaochenggong"];
    //签到按钮
    UIButton * cancelBtn=[UIButton buttonWithType:UIButtonTypeCustom];
    cancelBtn.frame=CGRectMake(55.5*PER_WIDTH, tipView.height-54*PER_HEIGHT, 190*PER_WIDTH, 39*PER_WIDTH);
    cancelBtn.layer.cornerRadius=cancelBtn.height/2;
    cancelBtn.backgroundColor=TINK_COLOR;
    cancelBtn.titleLabel.font=[UIFont fontWithName:HSGBW3 size:16];
    cancelBtn.titleLabel.font=[UIFont systemFontOfSize:16*PER_HEIGHT];
    [cancelBtn setTitle:@"知道了" forState:0];
    [cancelBtn setTitleColor:WHITE_COLOR forState:0];
    [cancelBtn addTarget:self action:@selector(know) forControlEvents:UIControlEventTouchUpInside];
    [tipView addSubview:cancelBtn];

    UILabel * lab1=[MyControl createLabelWithFrame:CGRectMake(0, cancelBtn.top-35*PER_HEIGHT, tipView.width, 14*PER_HEIGHT) Font:14 Text:@"明天继续签到可获得2积分哦" Color:BLACK_COLOR];
    lab1.textAlignment=NSTextAlignmentCenter;
    NSMutableAttributedString * attributed1=[[NSMutableAttributedString alloc]initWithString:lab1.text];
    [attributed1 setAttributes:@{NSForegroundColorAttributeName:TINK_COLOR,NSFontAttributeName:[UIFont fontWithName:HLT size:14]} range:NSMakeRange(9, 1)];
    lab1.attributedText=attributed1;
    [tipView addSubview:lab1];
    
    UILabel * lab2=[MyControl createLabelWithFrame:CGRectMake(0, lab1.top-25*PER_HEIGHT, tipView.width, 15*PER_HEIGHT) Font:15 Text:@"恭喜您,获得1积分" Color:BLACK_COLOR];
    lab2.textAlignment=NSTextAlignmentCenter;
    NSMutableAttributedString * attributed2=[[NSMutableAttributedString alloc]initWithString:lab2.text];
    [attributed2 setAttributes:@{NSForegroundColorAttributeName:TINK_COLOR,NSFontAttributeName:[UIFont fontWithName:HLT size:15]} range:NSMakeRange(6, 1)];
    lab2.attributedText=attributed2;
    [tipView addSubview:lab2];
    
    
    
}
-(void)know{
    [tipView removeFromSuperview];
    blureyView.hidden=YES;
    [self.view sendSubviewToBack:blureyView];
}
-(void)guanbi{
    [tipView removeFromSuperview];
    blureyView.hidden=YES;
    [self.view sendSubviewToBack:blureyView];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
